/*
 * Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.

For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
 */
package com.xinpan.exercise;

public class RemoveDuplicateFromSortedList {
    public ListNode deleteDuplicates(ListNode head) {
        // Start typing your Java solution below
        // DO NOT write main() function
        if(head == null)
            return null;
        ListNode pre = head;
        ListNode cur = head.next;
        while(cur != null)
        {
            if(pre.val == cur.val)
            {
                pre.next = cur.next;
                cur = pre.next;
            }
            else
            {
                pre = cur;
                cur = cur.next;
            }
        }
        
        return head;
    }
}
